<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/x-admin/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/x-admin/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/x-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/common.js"></script>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">文件管理</a>
            <a href="">文件列表</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body searchForm">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日期" name="startDate" id="startDate">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="结束日期" name="endDate" id="endDate">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" id="keyword" name="keyword" placeholder="桶名称/文件名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="syncStatus">
                                <option value="">同步状态</option>
                                <option value="0">未同步</option>
                                <option value="1">已同步</option>
                                <option value="2">同步失败</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <a class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></a>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table id="file_list_table" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
  var sdt = new Date();
  var edt = new Date();
  var result = ajaxRequest('${pageContext.request.contextPath}/common/getDate', {'type': '1'}, 'post');
  console.log(result);
  var obj = eval("(" + result + ")");
  if (null != obj && null != obj.success && obj.success == true) {
    sdt = obj.data.startDate;
    edt = obj.data.endDate;
  }
  layui.use(['table', 'laydate', 'form'], function () {
    var $ = layui.$;
    var laydate = layui.laydate;
    var table = layui.table;
    //执行一个laydate实例
    laydate.render({
      elem: '#startDate' //指定元素
      , value: sdt
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#endDate' //指定元素
      , value: edt
    });
    table.render({
      elem: '#file_list_table'
      , height: 'full-160'
      , even: true
      , size: 'sm'
      // , toolbar: '#toolbarDemo'
      , method: 'post'
      , url: '${pageContext.request.contextPath}/upload/file/list' //数据接口
      , where: {}
      , parseData: function (res) { //res 即为原始返回的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.message, //解析提示文本
          "count": res.data.total,//res.total, //解析数据长度
          "data": res.data.list //解析数据列表
        };
      }
      , id: 'fileTable'
      , page: true //开启分页
      , contentType: 'application/json'
      , limit: 20
      , limits: [20, 50, 100]
      , cols: [[ //表头
        {field: 'fileId', title: 'ID', width: 60, fixed: 'left', type: 'checkbox'}
        , {field: 'bucketName', title: '桶名称', width: 100}
        , {field: 'fileName', title: '文件名称', width: 200}
        , {field: 'fileType', title: '文件类型', width: 80}
        , {field: 'filePath', title: '文件路径', width: 300}
        , {field: 'netPath', title: '访问地址', width: 180}
        , {field: 'realFileName', title: '真实文件名', width: 180}
        , {field: 'fileSize', title: '文件大小', width: 180}
        , {
          field: 'syncStatus', title: '同步状态', width: 100,
          templet: function (d) {
            var syncStatus = d.syncStatus;
            if (syncStatus != null && syncStatus == '0') {
              return "未同步";
            } else if (syncStatus != null && syncStatus == '1') {
              return "已同步";
            } else if (syncStatus != null && syncStatus == '2') {
              return "同步失败";
            } else {
              return "同步异常";
            }
          }
        }
        , {field: 'updateTime', title: '更新时间', width: 180}
      ]],
      response: {
        statusCode: 1 //重新规定成功的状态码为 200，table 组件默认为 0
      }
    });
    //这里是查询
    var active = {
      reload: function () {
        var startDate = $('#startDate').val();
        var endDate = $('#endDate').val();
        var syncStatus = $("select[name='syncStatus'] option:selected").val();
        var keyword = $("#keyword").val();
        table.reload('fileTable', {
          where: {
            'startDate': startDate,
            'endDate': endDate,
            'syncStatus': syncStatus,
            'keyword': keyword
          }
          , page: {
            curr: 1 //重新从第 1 页开始
          }
        }, 'data');
      }
    };
    $('.searchForm .layui-btn').on('click', function () {
      /*var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';*/
      query();
    });

    function query() {
      var startDate = $('#startDate').val();
      var endDate = $('#endDate').val();
      var syncStatus = $("select[name='syncStatus'] option:selected").val();
      var keyword = $("#keyword").val();
      table.reload('fileTable', {
        where: {
          'startDate': startDate,
          'endDate': endDate,
          'syncStatus': syncStatus,
          'keyword': keyword
        }
        , page: {
          curr: 1 //重新从第 1 页开始
        }
      }, 'data');
    }
  });
</script>
</html>